package com.ai.platform.business.web;


import com.ai.platform.business.entity.BusiReport;
import com.ai.platform.core.annotation.RestInvokeService;
import com.ai.platform.core.controller.BaseController;
import com.ai.platform.core.exception.BusinessException;
import com.ai.platform.model.dto.Output;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;

/**
 * 报表
 *
 * @author yeyingsheng
 * @since 2018-06-01
 */
@Controller
@RequestMapping("/business/busiReport")
public class BusiReportController extends BaseController{


    /**
     * 报表首页
     * @return
     */
    @RequestMapping("index")
    public String toReport(){
        return "business/report/report";
    }

    /**
     * 查询报表数据
     * @return
     */
    @RequestMapping("reportList")
    @RestInvokeService(serviceName = "busiReportServiceImpl",method = "reportList")
    public Output reportList(){
        return this.getOutput();
    }

    /**
     * 查询报表内容数据
     * @return
     */
    @RequestMapping("reportListById")
    @RestInvokeService(serviceName = "busiReportServiceImpl",method = "reportListById")
    public Output reportListById(){
        return this.getOutput();
    }


    /**
     * 查询报表数据
     * @return
     */
    @RequestMapping("reportChartListByReportId")
    @RestInvokeService(serviceName = "busiReportServiceImpl",method = "reportChartListByReportId")
    public Output reportChartListByReportId(){
        return this.getOutput();
    }

    /**
     * 报表展示
     * @return
     */
    @RequestMapping("reportView/{reportId}")
    public ModelAndView toReportView(@PathVariable(name="reportId") String reportId, ModelAndView modelAndView){
        //根据参数查询
        Output output=this.getControlService().execute("busiReportServiceImpl","reportListById"
                ,"reportId",reportId);
        BusiReport busiReport= (BusiReport) output.getData();
        if(null==busiReport){
            throw new BusinessException("报表不存在");
        }
        modelAndView.setViewName("business/report/report-view");
        modelAndView.addObject("report",busiReport);
        return modelAndView;
    }

    /**
     * 查询报表指标数据
     * @return
     */
    @RequestMapping("reportChartDataById")
    @RestInvokeService(serviceName = "busiReportServiceImpl",method = "reportChartDataById")
    public Output reportChartDataById(){
        return this.getOutput();
    }

}

